package com.cmas.platform.controller;

import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.aidex.common.annotation.DataSource;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.TableDataInfo;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.enums.DataSourceType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.common.core.controller.BaseController;
import com.aidex.framework.cache.DictUtils;

import com.cmas.platform.domain.ApproveRecord;
import com.cmas.platform.vo.OperatorApplyVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.cmas.platform.domain.OperatorApply;
import com.cmas.platform.service.OperatorApplyService;


/**
 * 运营申请表Controller
 * @author su
 * @email 1218819874@qq.com
 * @date 2024-06-01
 */
@DataSource(value = DataSourceType.SLAVE)
@RestController
@RequestMapping("/platform/operatorApply")
public class OperatorApplyController extends BaseController  {

    @Autowired
    private OperatorApplyService operatorApplyService;

    /**
     * 查询运营申请表列表
     */
    @PreAuthorize("@ss.hasPermi('platform:operatorApply:list')")
    @GetMapping("/list")
    public R<TableDataInfo> list(OperatorApply operatorApply) {
        startPage();
        List<OperatorApplyVo> list = operatorApplyService.selectOperatorApplyVoList(operatorApply);
        return R.data(getDataTable(list));
    }

    /**
     * 获取运营申请表详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:operatorApply:query')")
    @GetMapping(value = "/{id}")
    public R<OperatorApply> detail(@PathVariable("id") String id) {
        return R.data(operatorApplyService.getById(id));
    }

    /**
     * 新增运营申请表
     */
    @PreAuthorize("@ss.hasPermi('platform:operatorApply:add')")
    @Log(title = "运营申请表", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  OperatorApply operatorApply) {
        return R.data(operatorApplyService.saveOperatorApply(operatorApply));
    }

    /**
     * 修改运营申请表
     */
    @PreAuthorize("@ss.hasPermi('platform:operatorApply:edit')")
    @Log(title = "运营申请表", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated OperatorApply operatorApply) {
        return R.data(operatorApplyService.updateOperatorApply(operatorApply));
    }


    /**
     * 审核申请
     */
    @PreAuthorize("@ss.hasPermi('platform:operatorApply:add')")
    @Log(title = "审核申请", businessType = BusinessType.INSERT)
    @PostMapping("/approve")
    public R approve(@RequestBody @Validated ApproveRecord approveRecord) {
        operatorApplyService.approve(approveRecord);
        return R.success("审核成功");
    }

    /**
     * 删除运营申请表
     */
    @PreAuthorize("@ss.hasPermi('platform:operatorApply:remove')")
    @Log(title = "运营申请表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.data(operatorApplyService.removeByIds(Arrays.asList(ids)));
    }


    /**
     * 导出运营申请表列表
     */
    @PreAuthorize("@ss.hasPermi('platform:operatorApply:export')")
    @Log(title = "运营申请表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(OperatorApply operatorApply) {
        List<OperatorApply> list = operatorApplyService.selectOperatorApplyList(operatorApply);
        ExcelUtil<OperatorApply> util = new ExcelUtil<OperatorApply>(OperatorApply.class);
        return util.exportExcel(list, "运营申请表数据");
    }
	
    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

    // ***用户系统位置戳****

    /**
     * 用户运营申请申请
     * @return
     */
    @GetMapping("/apply")
    public R<?> apply() {
        return R.data(operatorApplyService.apply());
    }

    /**
     * 查询申请剩余时间（30天内只能申请一次）
     * @return
     */
    @GetMapping( "/remainingTime")
    public R<?> remainingTime() {
        return R.data(operatorApplyService.remainingOperatorApplyTime());
    }
}
